<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/themes/admin/css/font.css">
    <link rel="stylesheet" href="/themes/admin/css/xadmin.css">
</head>
<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form">
                        {volist name= "ruleList[0]" id="vo"}
                        <blockquote class="layui-elem-quote">{$vo.title}</blockquote>
                        {notempty name="ruleList[$vo.id]"}
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                {volist name="ruleList[$vo.id]" id="v"}
                                <input type="checkbox" value="{$v.id}" id="{$v.id}" name="ruleItem" title="{$v.title}">
                                {/volist}
                            </div>
                        </div>
                        {/notempty}
                        {/volist}
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" onclick="saveRule()" class="layui-btn layui-btn-normal">立即提交</button>
                                <button type="button" onclick="javascript:history.back(-1)" class="layui-btn layui-btn-primary">返回</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/themes/admin/lib/layui/layui.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="/themes/admin/js/xadmin.js"></script>
<script>
    (function(){
        layui.use('form')
        layui.use('layer')
        $.ajax({
            type:"POST",
            data:{id:"{$Request.get.id}"},
            url:"/admin/user/groupRule",
            success:function (data) {
                $.each(data,function (index,item) {
                    $("#"+item).attr("checked","checked");
                    layui.form.render('checkbox');
                })
            }
        })
    })();

    var saveRule = function(){
        var ruleIdList = [];

        $('input[name="ruleItem"]:checked').each(function(){
            ruleIdList.push($(this).val());
        });
        var data = {"groupId":"{$Request.get.id}","ruleIdList":ruleIdList}
        $.ajax({
            type:"POST",
            data:data,
            url:"/admin/user/saveRule",
            success:function(e){
                if(e.code == 1){
                    layer.msg(e.msg,{icon:1});
                }else {
                    layer.msg(e.msg,{icon:2});
                }
            }
        });
    }
</script>
</body>
</html>